package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.commons.pojo.vo.PageData;
import cn.tedu.csmall.commons.web.JsonResult;
import cn.tedu.csmall.product.pojo.param.AlbumAddNewParam;
import cn.tedu.csmall.product.pojo.param.PictureAddNewParam;
import cn.tedu.csmall.product.pojo.vo.BrandListItemVO;
import cn.tedu.csmall.product.pojo.vo.PictureListItemVO;
import cn.tedu.csmall.product.service.IPictureService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/picture")
@Api(tags = "05. 图片管理模块")
@Validated
public class PictureController {
    @Autowired
    IPictureService pictureService;

    @PostMapping("/add-new")
    @ApiOperation("添加图片")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(@Valid PictureAddNewParam pictureAddNewParam) {
        log.debug("开始处理【添加图片】的请求，参数：{}", pictureAddNewParam);
        pictureService.addNew(pictureAddNewParam);
        log.debug("处理【添加图片】的请求，完成！");
        return JsonResult.ok();
    }

    @GetMapping("/list")
    @ApiOperation("根据相册id查询图片列表")
    @ApiOperationSupport(order =440)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "albumId",value = "相册ID",paramType = "query")
    })
    public JsonResult listByAlbumId(@Range(min = 1,message = "查询失败，请提供正确的id！") @RequestParam Long albumId) {
        log.debug("开始处理【根据相册id查询图片列表】的请求，参数：{}", albumId);
        List<PictureListItemVO> pictureListItemVOList = pictureService.listByAlbumId(albumId);
        return JsonResult.ok(pictureListItemVOList);
    }
}
